package cn.zwx.member.svc.controller.group;

import cn.zwx.base.entity.ResponseEntity;
import cn.zwx.base.exception.BizWrapException;
import cn.zwx.base.utils.PageUtil;
import cn.zwx.member.svc.dto.MemberGroupCreateDTO;
import cn.zwx.member.svc.dto.MemberGroupPageDTO;
import cn.zwx.member.svc.dto.MemberGroupUpdateDTO;
import cn.zwx.member.svc.service.MemberGroupService;
import cn.zwx.member.svc.vo.MemberGroupSimpleVO;
import cn.zwx.member.svc.vo.MemberGroupVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author zhangwenxue
 */
@RestController
@Api(tags = "会员分组相关接口")
@RequestMapping("/member/group")
public class MemberGroupController {
    private final MemberGroupService memberGroupService;

    public MemberGroupController(MemberGroupService memberGroupService) {
        this.memberGroupService = memberGroupService;
    }

    @PostMapping("/create")
    @ApiOperation("创建用户分组")
    public ResponseEntity<Long> createGroup(@Valid @RequestBody MemberGroupCreateDTO dto) throws BizWrapException {
        return ResponseEntity.success(memberGroupService.createGroup(dto));
    }

    @PutMapping("/update")
    @ApiOperation("更新用户分组")
    public ResponseEntity<Boolean> updateGroup(@Valid @RequestBody MemberGroupUpdateDTO dto) throws BizWrapException {
        return ResponseEntity.success(memberGroupService.updateGroup(dto));
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除用户分组")
    public ResponseEntity<Boolean> deleteGroup(@Valid@ApiParam(value = "用户分组id",required = true) @RequestParam("id") Long id) throws BizWrapException {
        return ResponseEntity.success(memberGroupService.deleteGroup(id));
    };

    @GetMapping("/get")
    @ApiOperation("获得用户分组")
    public ResponseEntity<MemberGroupVO> getGroup(@Valid@ApiParam(value = "用户分组id",required = true) @RequestParam("id") Long id){
        return ResponseEntity.success(memberGroupService.getGroup(id));
    }

    @GetMapping("/list-all-simple")
    @ApiOperation(value = "获取会员分组精简信息列表-只包含被开启的会员分组，主要用于前端的下拉选项")
    public ResponseEntity<List<MemberGroupSimpleVO>> getSimpleGroupList(){
        return ResponseEntity.success(memberGroupService.getSimpleGroupList());
    }


    @GetMapping("/page")
    @ApiOperation(value = "获得用户分组分页")
    public ResponseEntity<PageUtil<MemberGroupVO>> getGroupPage(@Valid MemberGroupPageDTO pageDTO){
        return ResponseEntity.success(memberGroupService.getGroupPage(pageDTO));
    };
}
